//
//  EFOrderLogisticsInformationViewController.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/9.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFOrderLogisticsInformationViewController.h"
#import "EFOrderLogisticsInformationViewItem.h"

@interface EFOrderLogisticsInformationViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(strong,nonatomic)UIView* topBgView;
@property(strong,nonatomic)UILabel* titleLabel;
@property(strong,nonatomic)UIView* topLine;

@property(strong,nonatomic)NSMutableArray* dataArray;
@property(strong,nonatomic)UITableView* tableView;
 
@end

@implementation EFOrderLogisticsInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (instancetype)init
{
    self = [super init];
    if (self) {
        self.title = @"物流信息";
        self.dataArray = [NSMutableArray array];
    }
    return self;
}

-(void)initView{
    [self.topBgView addSubview:self.titleLabel];
    [self.topBgView addSubview:self.topLine];
    [self.view addSubview:self.topBgView];
    [self.view addSubview:self.tableView];
    
    [self.titleLabel setText:@"顺丰速递：23540287"];
    [self.titleLabel sizeToFit];
    
    EFOrderLogisticsInformationViewItem* item = [[EFOrderLogisticsInformationViewItem alloc] init];
    item.address = @"已到达安华桥客运中心，正在安排派送...";
    item.time = @"2017-01-09  12:08:10";
    item.bFirst = true;
    [self.dataArray addObject:item];
    
    EFOrderLogisticsInformationViewItem* item2 = [[EFOrderLogisticsInformationViewItem alloc] init];
    item2.address = @"已到达安华桥客运中心，正在安排派送...";
    item2.time = @"2017-01-09  12:08:10";
    [self.dataArray addObject:item2];
    
    EFOrderLogisticsInformationViewItem* item3 = [[EFOrderLogisticsInformationViewItem alloc] init];
    item3.address = @"已到达安华桥客运中心，正在安排派送...";
    item3.time = @"2017-01-09  12:08:10";
    [self.dataArray addObject:item3];
    
    EFOrderLogisticsInformationViewItem* item4 = [[EFOrderLogisticsInformationViewItem alloc] init];
    item4.address = @"已到达安华桥客运中心，正在安排派送...";
    item4.time = @"2017-01-09  12:08:10";
    [self.dataArray addObject:item4];
    
    
    EFOrderLogisticsInformationViewItem* item5 = [[EFOrderLogisticsInformationViewItem alloc] init];
    item5.address = @"已到达安华桥客运中心，正在安排派送...";
    item5.time = @"2017-01-08  11:08:10";
    item5.bLast = true;
    [self.dataArray addObject:item5];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ICTableViewItem *item = self.dataArray[indexPath.row];
    return item.viewHeight;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ICTableViewItem* item = self.dataArray[indexPath.row];
    NSString *identifier = NSStringFromClass(item.viewClass);
    ICTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil){
        cell = [[item.viewClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if ([item isKindOfClass:[ICTableViewItem class]]) {
        [cell setObject:item];
    }
    return cell;
}

-(UIView *)topBgView{
    if(_topBgView == NULL){
        _topBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 53)];
        _topBgView.backgroundColor = [UIColor whiteColor];
    }
    return _topBgView;
}

-(UILabel *)titleLabel{
    if(_titleLabel == NULL){
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 40, 15)];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = kBlack333;
        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        _titleLabel.left = 20;
        _titleLabel.top = 17;
    }
    return _titleLabel;
}

-(UIView *)topLine{
    if(_topLine == NULL){
        _topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 40, 1)];
        _topLine.backgroundColor = RGBCOLOR(0xECECEC);
        _topLine.left = 20;
        _topLine.top = self.topBgView.height - 1;
    }
    return _topLine;
}


- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kStatusBarHeight - self.topBgView.height)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.top = self.topBgView.bottom;
    }
    return _tableView;
}

@end
